//-----------------------------------------------------------------------------
//<filedescription file="ActionsCompletionWizardPageControl.cs" company="Microsoft">
//  <copyright>
//     Copyright (c) 2005, 2010 Microsoft Corporation.  All rights reserved.
//  </copyright>
//  <purpose>
//     Control to be placed on ActionsWizardPage.
//  </purpose>
//  <notes>
//  </notes>
//</filedescription>
//-----------------------------------------------------------------------------

#region Using directives

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using DevelopStudio.Control.Basic;
using DevelopStudio.Basic;

#endregion

namespace DevelopStudio.Control.Commit
{
    /// <summary>
    /// The control for an ActionsWizardPage.
    /// </summary>
    public partial class ActionsCompletionWizardPageControl : ActionsWizardPageControlBase
    {
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Sets the caption string value.
        /// </summary>
        /// <value></value>
        public override string PageTitle
        {
            set
            {
#if (DEBUG)
                //ConnectionManagerBase.SmsTraceSource.TraceEvent(System.Diagnostics.TraceEventType.Error, 1, "Do not use page.PageTitle on the Completion Page");
                //Debug.Assert(false, "Do not use page.PageTitle on the Completion Page");
#endif
            }
            get { return labelCaption.Text; }
        }

        /// <summary>
        /// Sets the proceed message string value.
        /// </summary>
        /// <value></value>
        public override string ProceedMessage
        {
            set { labelProceed.Text = value; }
            get { return labelProceed.Text; }
        }

        /// <summary>
        /// Gets the RTF box.
        /// </summary>
        /// <value></value>
        internal override WpfSummaryBox SummaryBox
        {
            get
            {
                return wpfSummaryBox;
            }
        }

        /// <summary>
        /// ctor
        /// </summary>
        public ActionsCompletionWizardPageControl()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            // Make caption be "Big Blue Text".
            labelCaption.Font = new Font(labelCaption.Font.Name,
                (int)(labelCaption.Font.Size * 1.5F),
                FontStyle.Regular,
                labelCaption.Font.Unit,
                labelCaption.Font.GdiCharSet,
                labelCaption.Font.GdiVerticalFont);
            labelCaption.ForeColor = SystemColors.HotTrack;
        }

        /// <summary>
        /// 
        /// </summary>
        public override void OnActivated()
        {
            base.OnActivated();

            // What were the results?
            SmsSummaryAction.ActionStatus maxState = SmsSummaryAction.ActionStatus.NotStarted;
            IEnumerable<SmsSummaryItem> summaryItems = this.GetSummaryItems();
            if (summaryItems == null)
            {
                maxState = SmsSummaryAction.ActionStatus.CompleteWithErrors;
            }
            else
            {
                foreach (SmsSummaryItem var in summaryItems)
                {
                    SmsSummaryAction.ActionStatus resultState = GetResultState(var);
                    if (resultState > maxState)
                    {
                        maxState = resultState;
                    }
                }
            }

            // Update the UI to reflect the results.
            Icon icon;
            string pageTitleFormat;
            switch (maxState)
            {
                case SmsSummaryAction.ActionStatus.CompleteWithErrors:
                    icon = Properties.Resources.critical;
                    pageTitleFormat = Properties.Resources.ActionResultErrorDescription;
                    break;

                case SmsSummaryAction.ActionStatus.CompleteWithWarnings:
                    icon = Properties.Resources.warning;
                    pageTitleFormat = Properties.Resources.ActionResultWarningDescription;
                    break;

                default: // SmsSummaryAction.ActionStatus.CompleteWithSuccess
                    icon = Properties.Resources.ok;
                    pageTitleFormat = Properties.Resources.ActionResultSuccessDescription;
                    break;
            }

            //Set the message at the top of the page.
            pictureBoxState.Image = new Bitmap(icon.ToBitmap(), pictureBoxState.Size);
            labelCaption.Text = string.Format(CultureInfo.CurrentCulture, pageTitleFormat, this.ParentForm.Text);

            //Set the message at the bottom of the page.
            if (string.IsNullOrEmpty(ConfirmationCloseMessage) == false)
            {
                ProceedMessage = ConfirmationCloseMessage;
            }
        }

        private static SmsSummaryAction.ActionStatus GetResultState(SmsSummaryItem item)
        {
            SmsSummaryActionGroup group = item as SmsSummaryActionGroup;
            if (group != null)
            {
                SmsSummaryAction.ActionStatus maxState = SmsSummaryAction.ActionStatus.NotStarted;
                foreach (SmsSummaryAction action in group)
                {
                    if (action.Status > maxState)
                    {
                        maxState = action.Status;
                    }
                }
                return maxState;
            }

            return ((SmsSummaryAction)item).Status;
        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ActionsCompletionWizardPageControl));
            this.labelDescription = new System.Windows.Forms.Label();
            this.elementHostSummaryBox = new System.Windows.Forms.Integration.ElementHost();
            this.wpfSummaryBox = new WpfSummaryBox();
            this.labelProceed = new System.Windows.Forms.Label();
            this.labelCaption = new System.Windows.Forms.Label();
            this.pictureBoxState = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBoxState)).BeginInit();
            this.SuspendLayout();
            // 
            // labelDescription
            // 
            resources.ApplyResources(this.labelDescription, "labelDescription");
            this.labelDescription.Name = "labelDescription";
            // 
            // elementHostSummaryBox
            // 
            resources.ApplyResources(this.elementHostSummaryBox, "elementHostSummaryBox");
            this.elementHostSummaryBox.BackColor = System.Drawing.SystemColors.Window;
            this.elementHostSummaryBox.Name = "elementHostSummaryBox";
            this.elementHostSummaryBox.Child = this.wpfSummaryBox;
            // 
            // labelProceed
            // 
            resources.ApplyResources(this.labelProceed, "labelProceed");
            this.labelProceed.Name = "labelProceed";
            // 
            // labelCaption
            // 
            resources.ApplyResources(this.labelCaption, "labelCaption");
            this.labelCaption.Name = "labelCaption";
            // 
            // pictureBoxState
            // 
            resources.ApplyResources(this.pictureBoxState, "pictureBoxState");
            this.pictureBoxState.Name = "pictureBoxState";
            this.pictureBoxState.TabStop = false;
            // 
            // ActionsCompletionWizardPageControl
            // 
            this.Controls.Add(this.pictureBoxState);
            this.Controls.Add(this.labelCaption);
            this.Controls.Add(this.labelProceed);
            this.Controls.Add(this.elementHostSummaryBox);
            this.Controls.Add(this.labelDescription);
            this.Name = "ActionsCompletionWizardPageControl";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBoxState)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private Label labelCaption;
        private Label labelDescription;
        private System.Windows.Forms.Integration.ElementHost elementHostSummaryBox;
        private WpfSummaryBox wpfSummaryBox;
        private PictureBox pictureBoxState;
        private Label labelProceed;
        #endregion
    }
}

